package cn.tedu.front.search.service.impl;

import cn.tedu.common.pojo.vo.PageData;
import cn.tedu.front.search.dao.persist.repository.ICompanyRepository;


import cn.tedu.front.search.dao.search.ICompanyCustomSearchRepository;
import cn.tedu.front.search.dao.search.ICompanySearchRepository;
import cn.tedu.front.search.pojo.po.CompanyPO;
import cn.tedu.front.search.service.ICompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CompanyService implements ICompanyService {

    @Autowired
    private ICompanyRepository repository;
    @Autowired
    private ICompanySearchRepository searchRepository;
    @Autowired
    private ICompanyCustomSearchRepository elasticSearch;


    @Override
    public void saveCompany() {
        log.info("开始向ES写入数据.......");
        Integer pageNum=1;
        Integer pageSize=10;
        PageData<CompanyPO> companyPOPageData = repository.listSearch(pageNum, pageSize);
        List<CompanyPO> searchList = companyPOPageData.getList();
        for (CompanyPO companyPO : searchList) {
            elasticSearch.save(companyPO);
        }
    }

    @Override
    public PageData<CompanyPO> getCompany(String keyword, Integer pageNum, Integer pageSize) {
        log.info("开始处理【搜索公司】的业务，关键词：{}, 页码：{}，每页记录数：{}\""+keyword,pageNum,pageSize);
         return searchRepository.search(keyword, pageNum, pageSize);
    }
}
